package marionito.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public final class Util {
	public static void checkObject(Object o) {
		if (o == null)
			throw new NullPointerException();
	}

	public static void checkString(String s) {
		checkObject(s);
		if (s.trim().equals(""))
			throw new IllegalArgumentException();
	}

	public static void checkNegativeOrZero(double d) {
		if (d > 0.0)
			throw new IllegalArgumentException();
	}

	public static void checkPositiveOrZero(double d) {
		if (d < 0)
			throw new IllegalArgumentException();
	}

	public static void checkPositive(double d) {
		if (d <= 0.00001)
			throw new IllegalArgumentException();
	}

	public static void checkPositive(int i) {
		if (i <= 0)
			throw new IllegalArgumentException();
	}

	public static void checkEmail(String s) {
		checkString(s);
		Pattern pattern;
		Matcher matcher;

		pattern = Pattern.compile("^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@"
				+ "[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
		matcher = pattern.matcher(s);
		if (!matcher.matches())
			throw new IllegalArgumentException();
	}

	public static void checkValeurJeton(int v) {
		if (v < 1 || v > 12)
			throw new IllegalArgumentException();
	}

	public static void checkNumCase(int n) {
		checkPositive(n);
		if (n > 36 || n < 1)
			throw new IllegalArgumentException();
	}
}
